public class Test7 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread() {
            @Override
            public void run() {
                //Thread.currentThread().isInterrupted()默认为false
                try {
                    while (!Thread.currentThread().isInterrupted()) {
                        System.out.println("正在打印1");
                    }
                    System.out.println("=====进程结束1=====");

                    while (!Thread.interrupted()) {
                        System.out.println("正在打印2");
                        Thread.sleep(1000);
                    }
                    System.out.println("=====进程结束2=====");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
        Thread.sleep(1000);
        //设置标记值为true
        thread.interrupt();
        System.out.println("=============");
        Thread.sleep(3000);
        System.out.println(thread.getState());
        System.out.println(thread.isAlive());
    }
}
